home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86v307b.arc / 05EXCLUS.DOC next >
Text File  |  1987-07-13  |  9KB  |  203 lines

  1. CHAPTER 5   SOME EXCLUSIVE FEATURES OF A86                5-1
  2.  
  3. Since this is the start of the A86VxxxB.ARC file, I'll repeat 
  4. here that the entire A86 package is Copyright (C)1986--1987 Eric 
  5. Isaacson.  All rights reserved.  If this is all you've got, you 
  6. need to get A86VxxxA.ARC and A86VxxxC.ARC, which contain the 
  7. program and the rest of the manual. 
  8.  
  9.  
  10. The IF Statement
  11.  
  12. As a "nudge" in the direction of structured programming, A86 
  13. offers the IF statement.  Suppose you want to conditionally skip 
  14. around just one instruction.  Ordinarily, this would require, for 
  15. example: 
  16.  
  17.   JNZ >L1    ; skip the following move if NZ
  18.   MOV AX,BX  ; make this move only if Z
  19. L1:          ; this label exists only for the above skip
  20.  
  21. You may replace the above code with the single line:
  22.  
  23.   IF Z MOV AX,BX
  24.  
  25. The above line generates exactly the same code as the previous 3 
  26. lines-- a conditional jump of the opposite condition, around the 
  27. statement given in the tail of the IF statement.  The statement 
  28. can be a macro call, giving you the opportunity to skip something 
  29. more complicated.
  30.  
  31. You may use any condition that would follow the "J" in a 
  32. conditional jump instruction, except CXZ, which does not have a 
  33. reverse condition.  The assembler interprets the condition by 
  34. appending a "J" to the beginning of the condition; so that the 
  35. symbols "C", "NC", "Z", "NZ", etc. are not reserved by the 
  36. assembler, and can be defined in other contexts.  
  37.  
  38.  
  39. Multiple operands to PUSH, POP, INC, DEC
  40.  
  41. A86 will accept any number of register operands for the 
  42. instructions PUSH, POP, INC, and DEC; it will generate the 
  43. appropriate machine instruction for each operand.  For example, 
  44. the statement PUSH AX,BX is the same as the two statements PUSH 
  45. AX and PUSH BX.  
  46.  
  47. A numeric operand appearing in an INC or DEC statement will cause 
  48. the previous INC(s) or DEC(s) to be propagated that number of 
  49. times.  For example, the statement INC AX,4 will generate 4 INC 
  50. AX instructions.  The statement DEC AL,BX,2 will generate DEC AL, 
  51. DEC BX, DEC AL, DEC BX.  Sorry, numeric operands are not allowed 
  52. if any of the operands affected was a forward-reference or 
  53. relocatable quantity; e.g., INC FOO,2 where FOO is undefined.  In 
  54. most such cases, you'll want to code the more effiecient ADD 
  55. FOO,2 anyway.
  56.  
  57.  
  58.                                                           5-2
  59. Conditional Return Instructions
  60.  
  61. Programmers accustomed to the conditional-return instructions of 
  62. the 8080/Z80 will appreciate the following feature: A86 allows 
  63. the operand to a conditional jump instruction to be one of the 
  64. three RET instructions RET, RETF, or IRET.  The assembler will 
  65. find a nearby return-instruction of the indicated flavor, and use 
  66. that as the target for the conditional jump.  For example, JZ RET 
  67. is the replacement for the 8080's RZ return-if-zero instruction.  
  68. In other 8086 assembly languages, you have to find the nearby 
  69. instruction yourself, attach a label to it, and use that label.  
  70. Note that it does not suffice to attach a label to a single RET 
  71. instruction and use that label throughout the program: the range 
  72. of conditional jumps is only 128 bytes in either direction.  
  73.  
  74. What happens if A86 does not find a nearby return instruction?  
  75. In that case, A86 issues an error, "02 Jump > 128", for the next 
  76. matching return-instruction in the program.  If there is no 
  77. subsequent return-instruction, the return-mnemonic will appear as 
  78. an undefined symbol at the end of the program.   In either case, 
  79. you correct the problem by inserting a free-standing return-
  80. instruction at some nearby point in the program, where it will 
  81. not affect the existing code (typically following an 
  82. unconditional JMP instruction).  If there is no good place to 
  83. insert a return-instruction, you can always replace the "Jcond 
  84. RET" with an "IF cond RET".  
  85.  
  86.  
  87. A86 extensions to the MOV instruction
  88.  
  89. There are a number of MOV instructions available in A86 that are 
  90. not a part of the machine instruction set.  
  91.  
  92. First, moves between segment registers are allowed.  For example, 
  93. if you code MOV ES,DS  , the assembler will generate a PUSH DS 
  94. followed by a POP ES; which will effect the move that you 
  95. intended.  
  96.  
  97. Second, MOV allows 3 operands.  A statement MOV x,y,z is 
  98. equivalent to the two statements MOV y,z followed by MOV x,y.  
  99. Sorry, but segment-overrides are not allowed in conjunction with 
  100. 3-operand MOVs.  The override preceding the MOV is ambiguous in 
  101. its meaning; and overrides within operands cannot be handled 
  102. correctly by A86.  You'll have to code two MOV instructions if 
  103. you want either or both to have a segment override.
  104.  
  105.  
  106. Local Labels
  107.  
  108. If you examine most assembly-language program symbol tables, you 
  109. will find that the symbols can be partitioned into two levels of 
  110. significance.   About half the symbols are the names of 
  111. procedures and variables having global significance.  If the 
  112. names of these symbols are chosen intelligently and carefully, 
  113. the program's readability improves drastically. (They usually 
  114. aren't chosen well, most often because the assembler restricts 
  115. symbols to 6 letters, or because the programmer's habits are 
  116. influenced by such assemblers.) 
  117.                                                           5-3
  118.  
  119. The other half of the symbols in a program have a much lower, 
  120. local significance.  They are only place-markers used to 
  121. implement small loops and local branching (e.g., "skip the next 2 
  122. instructions if the Z-flag is set").  Assigning full-blown names 
  123. to these labels reduces the readability of your program in two 
  124. ways:  First, it is harder to recognize local jumps for what they 
  125. are-- they are usually the assembly-language equivalent of high-
  126. level language constructs like IF statements and WHILE-loops.  
  127.  
  128. Second, it is harder to follow the global, significant symbols 
  129. because they are buried in a sea of the place-marker symbols in 
  130. the symbol table.  
  131.  
  132. A86 solves this problem with local symbols.  If a symbol in your 
  133. program consists of a single letter followed by one or more 
  134. decimal digits (L3, X123, Y37, etc.), then the symbol is a local 
  135. symbol.  Local symbols do not appear in the A86 XREF cross-
  136. reference listing. They can also be redefined to something 
  137. completely different later in the program.  
  138.  
  139. Because local labels can be redefined, you must take care to 
  140. specify which one you are referring to in your program.  If your 
  141. reference is a forward-reference (the label occurs further down 
  142. in the program from the reference), then the reference must be 
  143. preceded by a ">".  For example, 
  144.  
  145. L2:
  146.   MOVSB
  147.   INC BX
  148.   LOOP L2    ; lack of ">" means L2 is above this statement
  149.   .
  150.   .
  151.   JNZ >L2    ; ">" indicates L2 is below this statement
  152.   .
  153.   .
  154. L2:
  155.  
  156. I recommend that you assign all your local labels the names L0 
  157. through L9.  If your program is so complex that it needs more 
  158. than 10 place-holders in any one stretch of code, then that 
  159. stretch needs to be rewritten.  
  160.  
  161.  
  162.  
  163. Operands to AAM and AAD Instructions
  164.  
  165. Those of you who have examined 86-family opcodes with an eagle-
  166. eye will have noticed a somewhat spurious "0A" opcode generated 
  167. after every AAM or AAD instruction.  The opcode is there to 
  168. provide the constant divisor or multiplicand for the instruction.  
  169. Believe it or not, there wasn't enough room in the microcode of 
  170. the original 8086 to hold this constant!  Although Intel has 
  171. never announced the generality of AAM and AAD, it is there: you 
  172. can substitute any other constant for 0A (decimal 10), and that 
  173.                                                           5-4
  174.  
  175. constant will be used.  A86 supports this by letting you give a 
  176. constant byte-sized operand to AAM or AAD.  Particularly useful 
  177. are the instructions AAM 16, which unpacks AL into nibbles AH and 
  178. AL; and AAD 16, which reverses the process, packing nibbles AH 
  179. and AL into AL.  
  180.  
  181. WARNING: A couple of my users point out to me that the AAD 
  182. instruction with a general operand won't work on the NEC V20 and 
  183. V30 chips.  The operand is assumed to be 10 no matter what it 
  184. really is.  Since a large number of PC "speed-up" kits involve 
  185. switching to NEC chips, this will be seen on many PC's.  You 
  186. should not use AAD with an operand if you want your program to 
  187. run on everybody's machine.  Too bad.  AAM works fine, though. 
  188.  
  189.  
  190.  
  191. Single-Operand Forms of the TEST Instruction
  192.  
  193. A86 allows the TEST instruction to have a single operand, to set 
  194. the flags according to the value of the operand.  If the operand 
  195. is a register, A86 generates a TEST of the register with itself.  
  196. If the operand is a memory quantity, A86 generates a TEST of the 
  197. memory with the constant -1 (i.e., the quantity will be ANDed 
  198. with an all 1's constant).  For example, instead of TEST DL,DL, 
  199. you can code simply TEST DL.  Instead of TEST WVAR,0FFFF, you can 
  200. code simply TEST WVAR.  
  201.  
  202.  
  203.